"use strict";
let num = 123;
let myNull = null;
let myUndefined = undefined;
let myName = `${myUndefined}`;
function fnc1() {
    return;
}
function fnc2() {
    return undefined;
}
let obj1 = {};
let obj2 = {};
let obj3 = {
    id: 1,
    name: 'xxx',
    age: 18,
    sex: 'male',
    nickname: {
        name: 'liming'
    },
    cb: () => {
        return false;
    }
};
obj3.sex = 123;
console.log(obj3);
let obj4 = (name) => {
    return [1, 2, 3];
};
let arr = [
    { name: 'zhangsan', age: 18 },
    { name: 'lisi', age: 19 },
    { name: 'wangwu', age: 20 }
];
// 二维数组
let arr2 = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];
let arr3 = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];
// 大杂烩数组
let arr4 = [
    1,
    '2',
    true,
    { name: 'zhangsan', age: 18 },
    [1, 2, 3]
];
function a(...args) {
    console.log(args);
}
a(1, 2, 3);
// arguments
function b(...args) {
    console.log(arguments);
}
b(1, 2, 3, 4, 5);
function c(...args) {
    let a = arguments;
}
c(1, 2, 3, 4, 5);
function d(...args) {
    let a = arguments;
}
d(1, 2, 3, 4, 5);
console.log("--------------------函数--------------------");
// 函数
function add(a, b) {
    return a + b;
}
console.log(add(1, 2));
//  箭头函数写法
const add2 = (a, b) => {
    return a + b;
};
function user(user) {
    return user;
}
console.log(user({ username: "admin", password: "123456" }));
let obj5 = {
    arrNum: [1, 2, 3],
    add(num) {
        this.arrNum.push(num);
    }
};
obj5.add(4);
console.log(obj5.arrNum);
console.log("----------------函数重载-------------");
const admin = [1, 2, 3, 4, 5, 6];
function getAdmin(ids) {
    if (typeof ids == "number") {
        return admin.filter(v => v == ids);
    }
    else if (Array.isArray(ids)) {
        admin.push(...ids);
        return admin;
    }
    else {
        return admin;
    }
}
console.log(getAdmin());
// 联合类型
console.log("----------------联合类型-------------");
let fn = function (num) {
    return !!num;
};
console.log(fn(1));
// 交叉类型
console.log("----------------交叉类型-------------");
function personFn(man) {
    console.log(man);
}
personFn({ name: "zhangsan", age: 18, sex: "1" });
// 类型断言
console.log("----------------类型断言-------------");
function getLength(str) {
    console.log(str.length);
}
getLength("123456");
getLength(123456); //tip 类型断言只能欺骗编译器不报错，number类型是没有length的方法，所以是undefined
// 这个例子也证明了类型断言只能欺骗编译器，不会帮你转换为boolean类型
function getBolean(str) {
    return str;
}
console.log(getBolean(1));
// 内置对象
console.log("----------------内置对象-------------");
const date = new Date();
const reg = new RegExp("/\W/");
const error = new Error("错误");
const xhr = new XMLHttpRequest();
const math = new String();
let div = document.querySelectorAll("div");
let local = localStorage;
let loacltion = location;
let promise = new Promise((resolve, reject) => {
    resolve("成功");
});
promise.then(res => res.length);
let cookie = document.cookie;
// class
console.log("----------------class-------------");
class Dom {
    createElement(el) {
        return document.createElement(el);
    }
    setText(el, text) {
        el.textContent = text;
    }
    render(data) {
        let root = this.createElement(data.tag);
        if (data.children && Array.isArray(data.children)) {
            data.children.forEach(item => {
                this.render(item);
            });
        }
        else {
            let child = this.setText(root, data.text);
            root.appendChild(child);
        }
        return root;
    }
}
class Vue {
    constructor(options) {
        this.options = options;
        this.init();
    }
    init() {
        let data = {
            tag: "div",
            text: "",
            children: [
                { tag: "div", text: "我是子节点1" },
                { tag: "div", text: "我是子节点2" }
            ]
        };
    }
}
new Vue({
    el: "#app"
});
